/* 
练习题1 =============================================================
*/
/* let userName = ["老赵", "老李", "小传", "小黑"];
console.log(userName[parseInt(Math.random() * userName.length)]); */

/* 
练习题2 =============================================================
*/
/* let per = {
    sex: '',
    age: 19,
    like: '吃饭睡觉打豆豆',
    say: function () { 
        console.log('Hello!');
    },
    eat: function () { 
        console.log('tasty food!');
    }
}
console.log(per.sex);
console.log(per.age);
console.log(per.like);
per.say();
per.eat(); */

/* 
练习题3 =============================================================
*/
/* 
//利用题2的对象
per.eat();
per['eat'](); */

/* 
练习题4 =============================================================
*/
/* let quizzesNum = 8
let min = 0,max = 9
for (let i = 0;i < quizzesNum;i++) {
    let userNum = userInputNumberScope(min, max, `请输入竞猜数字(0-9)：\n剩余次数：${quizzesNum-i}`);
    let winNum = parseInt(Math.random() * (max + 1));
    winNum === userNum?alert(`恭喜！\n猜中号码！\n中奖号码：${winNum}`):alert(`很遗憾！\n未能猜中号码！\n\n您的号码：${userNum}\n中奖号码：${winNum}`)
}

// 工具函数 仅允许输入数字,限定数字范围,包含空输入的说明文字
function userInputNumberScope(min = 0,max = 1,hintInfo = `请输入数字：`,errScopeInfo = `超过数字范围！`, errInfoNaN = `非数字！`, errInfoNull = `输入为空！`) {
    let inputStr;
    for (let i = true; i ;) {
        inputStr = prompt(hintInfo);
        !inputStr ? alert(errInfoNull) : +inputStr || +inputStr+1? +inputStr > max || +inputStr < min ? alert(errScopeInfo) : i = false : alert(errInfoNaN)
    }
    return +inputStr;
} */

/* 
练习题5 =============================================================
*/

/* let R = parseInt(Math.random()*256);
let G = parseInt(Math.random()*256);
let B = parseInt(Math.random()*256);
        
document.write(`
    <div style="width: 300px; height: 300px; margin: 50px auto; background-color: rgb(${R},${G},${B})"></div>
    <h3 style="width: 300px;margin: 0px auto;text-align: center">
        <span style="color: red">R:${R}</span> - 
        <span style="color: green">G:${G}</span> - 
        <span style="color: blue">B:${B}</span>
    </h3>
`); */